<!--  是一个单独的轮播图组件-->
<template>
  <div class="banner">
    <el-carousel :interval="3500" arrow="never" :height="bannerHeight+'px'">
      <el-carousel-item v-for="item in Bannerdata" :key="item.id">
        <img ref="bannerHeight" @load="imgLoad" :src="item.src" alt="banner" style=" width: 400px;">
      </el-carousel-item>
    </el-carousel>
    
  </div>
</template>

<script>
import { banner } from "@/api/index"
export default {
    name: 'Banner',

    data() {
        return {
          bannerHeight:"",
          Bannerdata:[],
        };
    },

    mounted() {
      this.imgLoad();
      window.addEventListener('resize',()=>{
        this.bannerHeight=this.$refs.bannerHeight[0].height
        this.imgLoad();
      },false);
      

      let i =async()=>{
        let B =await banner()
        // console.log(B.data.banners);
        this.Bannerdata = B.data.banners
      }
      i()

    },

    methods: {
      imgLoad(){
        this.$nextTick(()=>{
          this.bannerHeight=this.$refs.bannerHeight[0].height;
        })
      }
    },
};
</script>

<style scoped>
.banner {
  max-width: 400px;
  margin: 0 auto;
  margin-top: 44px;
}
::v-deep .el-carousel__button{
  border-radius: 50%;
  width: 13px;
  height: 13px;
}
.el-carousel__item h3 {
  color: #008c8c;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.el-carousel__indicator {
  background-color: transparent;
  cursor: pointer;
  width: 25px !important;
}
</style>
